module FamilyTreeApi
  module Search

    class Event
      attr_accessor :type, :scope, :date, :place

      def self.parse event_elements
          events = event_elements.collect do |event_element|
            event = self.new
            event.type = event_element.attributes["type"]
            event.scope = event_element.attributes["scope"]
            event_element.children.each do |e|
              case e.name
              when 'date'
                e.children.each do |d|
                  event.date = d.content if d.name == 'original' && d.content != ''
                end
              when 'place'
                e.children.each do |p|
                  event.place = p.content if p.name == 'original' && p.content != ''
                end
              end
            end
            event
          end
      end
    end
  end
end